package com.ssy.lingxi.common.constant.marketing;

import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 商家优惠券类型枚举
 * @author yzc
 * @version 2.0.0
 * @date 2021/6/28
 */
public enum MerchantCouponTypeEnum {

    /**
     * 0元购买抵扣券 - 1
     */
    ZERO_DISCOUNT(1, "0元购买抵扣券"),

    /**
     * 通用优惠券 - 2
     */
    COMMON(2, "通用优惠券"),

    /**
     * 品类优惠券 - 3
     */
    CATEGORY(3, "品类优惠券"),

    /**
     * 品牌优惠券 - 4
     */
    BRAND(4, "品牌优惠券"),

    /**
     * 商品优惠券 - 5
     */
    COMMODITY(5, "商品优惠券");


    private final Integer code;
    private final String message;

    MerchantCouponTypeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static String getCodeMessage(Integer code) {
        MerchantCouponTypeEnum status = Arrays.stream(MerchantCouponTypeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return status == null ? "未知" : status.getMessage();
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getClass(), this.code);
    }

    public static MerchantCouponTypeEnum parse(Integer code) {
        return Arrays.stream(MerchantCouponTypeEnum.values()).filter(v -> v.getCode().equals(code)).findFirst().orElse(null);
    }

    /**
     * 暂不支持的优惠券（0元/品类/品牌）
     * @return
     */
    public static List<Integer> getNotSupportType(){
        return Stream.of(MerchantCouponTypeEnum.ZERO_DISCOUNT,MerchantCouponTypeEnum.CATEGORY,MerchantCouponTypeEnum.BRAND).map(MerchantCouponTypeEnum::getCode).collect(Collectors.toList());
    }
}